package com.movitech.mobile.cz.base.purchase.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.movitech.mobile.cz.base.common.license.LicenseUtil;
import com.movitech.mobile.cz.base.common.util.CommonConstants;
import com.movitech.mobile.cz.base.purchase.entity.WFlowFormPurchaseTeam;
import com.movitech.mobile.cz.base.purchase.mapper.WFlowFormPurchaseTeamMapper;
import com.movitech.mobile.cz.base.purchase.service.WFlowFormPurchaseTeamService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 流程表单-采购小组 服务实现类
 * </p>
 *
 * @author Movitech Mobile
 * @since 2018-03-15
 */
@Service
public class WFlowFormPurchaseTeamServiceImpl extends ServiceImpl<WFlowFormPurchaseTeamMapper, WFlowFormPurchaseTeam> implements WFlowFormPurchaseTeamService {
    @Override
    public List<WFlowFormPurchaseTeam> getTeamByFlowFormId(String flowFormId) {
        LicenseUtil.INSTANCE.validate();
        EntityWrapper entityWrapper = new EntityWrapper<>();
        WFlowFormPurchaseTeam wFlowFormPurchaseTeam = new WFlowFormPurchaseTeam();
        wFlowFormPurchaseTeam.setFlowFormId(flowFormId);
        wFlowFormPurchaseTeam.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
        entityWrapper.setEntity(wFlowFormPurchaseTeam);
        return selectList(entityWrapper);
    }

    @Override
    public List<WFlowFormPurchaseTeam> getTeamByFlowFormIdAndJob(String flowFormId, Integer... jobs) {
        LicenseUtil.INSTANCE.validate();
        EntityWrapper entityWrapper = new EntityWrapper<>();
        WFlowFormPurchaseTeam wFlowFormPurchaseTeam = new WFlowFormPurchaseTeam();
        wFlowFormPurchaseTeam.setFlowFormId(flowFormId);
        wFlowFormPurchaseTeam.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
        entityWrapper.setEntity(wFlowFormPurchaseTeam);
        entityWrapper.in("purchase_job",jobs);
        return selectList(entityWrapper);
    }

    @Override
    public WFlowFormPurchaseTeam getTeamByFormIdAndUserId(String formId, String userId) {
        LicenseUtil.INSTANCE.validate();
        EntityWrapper entityWrapper = new EntityWrapper<>();
        WFlowFormPurchaseTeam wFlowFormPurchaseTeam = new WFlowFormPurchaseTeam();
        wFlowFormPurchaseTeam.setFlowFormId(formId);
        wFlowFormPurchaseTeam.setUserId(userId);
        wFlowFormPurchaseTeam.setDelFlag(CommonConstants.DEL_FLAG_NORMAL);
        entityWrapper.setEntity(wFlowFormPurchaseTeam);
        return selectOne(entityWrapper);
    }

    @Override
    public Integer selectCountByFormId(String formId) {
        LicenseUtil.INSTANCE.validate();
        return selectCount(new EntityWrapper<WFlowFormPurchaseTeam>().
                eq("flow_form_id",formId).eq("del_flag",CommonConstants.DEL_FLAG_NORMAL));
    }
}

